package com.device.operating.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.device.operating.dao.FieldresRepository;
import com.device.operating.dao.UserRepository;
import com.device.operating.entity.Fieldres;
import com.device.operating.service.FieldresService;

@Service("FieldresService")
@Transactional(propagation=Propagation.REQUIRED)
public class FieldresServiceImpl implements FieldresService{

	@Autowired
	private FieldresRepository FieldresRepository;

	@Override
	public List<Fieldres> queryfield(String fieldbelong, boolean ifshow) {
		// TODO Auto-generated method stub
		return  FieldresRepository.findByFieldbelongAndIfshow(fieldbelong, ifshow);
	}

	@Override
	public List<Fieldres> queryfec(String fieldbelong, boolean ifsec) {
		// TODO Auto-generated method stub
		return  FieldresRepository.findByFieldbelongAndIfsecOrderByFieldnumAsc(fieldbelong, ifsec);
	}

	@Override
	public List<Fieldres> queryallfield(String fieldbelong) {
		// TODO Auto-generated method stub
		return FieldresRepository.findByFieldbelong(fieldbelong);
	}

	@Override
	public void setfield(String fieldId, String sectype) {
		// TODO Auto-generated method stub
		Fieldres field=FieldresRepository.findOne(fieldId);
		field.setIfsec(true);
		field.setSectype(sectype);
		FieldresRepository.save(field);
	}

	@Override
	public void deletefieldbelong(String fieldbelong) {
		// TODO Auto-generated method stub
		List<Fieldres> lf=FieldresRepository.findByFieldbelong(fieldbelong);
		for(Fieldres field:lf)
		FieldresRepository.delete(field);
	}

	@Override
	public void updatefield(Fieldres fieldres) {
		// TODO Auto-generated method stub
		FieldresRepository.save(fieldres);
	}

	@Override
	public Fieldres quertone(String fieldresId) {
		// TODO Auto-generated method stub
		return FieldresRepository.findOne(fieldresId);
	}

	@Override
	public List<Fieldres> queryallfieldabs(String fieldbelong) {
		// TODO Auto-generated method stub
		return FieldresRepository.findByFieldbelongabs(fieldbelong);
	}

	@Override
	public Fieldres querybydvbelongandfieldcode(String dvbelong,
			String fieldcode) {
		// TODO Auto-generated method stub
		return FieldresRepository.findByFieldbelongAndFieldcode(dvbelong, fieldcode);
	}

	@Override
	public void addfield(Fieldres field) {
		// TODO Auto-generated method stub
		FieldresRepository.save(field);
	}

	@Override
	public void deletefield(String fieldId) {
		// TODO Auto-generated method stub
		FieldresRepository.delete(fieldId);
	}

	@Override
	public List<Fieldres> querybyfieldnum(String fieldbelong) {
		// TODO Auto-generated method stub
		return FieldresRepository.findByFieldbelongOrderByFieldnumAsc(fieldbelong);
	}
	
	
}
